package com.llsydn.service.remote;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

/**
 * @author lilinshen
 * @title 请填写标题
 * @description 请填写相关描述
 * @date 2018/9/29 11:20
 */
public class Student implements Parcelable {
    private int id;
    private String name;
    private double price;

    public Student(int id, String name, double price) {
        this.id = id;
        this.name = name;
        this.price = price;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    /**
     * 将当前对象的属性数据打成包，写到包对象中
     *
     * @param dest
     * @param flags
     */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        Log.e("TAG", "打包writeToParcel()");
        dest.writeInt(id);
        dest.writeString(name);
        dest.writeDouble(price);
    }

    // 添加一个静态成员,名为CREATOR,该对象实现了Parcelable.Creator接口
    public static final Parcelable.Creator<Student> CREATOR = new Parcelable.Creator<Student>() {
        //解包，读取包中的数据并封装成对象
        public Student createFromParcel(Parcel source) {
            Log.e("TAG", "createFromParcel()");
            return new Student(source.readInt(), source.readString(), source.readDouble());
        }

        //返回一个指定大小的对象容器
        public Student[] newArray(int size) {
            return new Student[size];
        }
    };

}
